<?php

namespace app\common\model;

use app\common\model\card\Dealer;
use think\Model;


class Message extends Model
{

    

    

    // 表名
    protected $name = 'message';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'sende_data_text',
        'type_text',
        'is_read_text'
    ];
    

    
    public function getSendeDataList()
    {
        return ['0' => __('Sende_data 0'), '1' => __('Sende_data 1'), '2' => __('Sende_data 2'), '3' => __('Sende_data 3'), '4' => __('Sende_data 4')];
    }

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2')];
    }

    public function getIsReadList()
    {
        return ['0' => __('Is_read 0'), '1' => __('Is_read 1')];
    }


    public function getSendeDataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sende_data']) ? $data['sende_data'] : '');
        $list = $this->getSendeDataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsReadTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_read']) ? $data['is_read'] : '');
        $list = $this->getIsReadList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getEnzdAttr($value, $data)
    {
        if($data["sende_data"]==0){
            //发送对象:0=用户,1=店铺,2=区域服务商,3=卡经销商,4=分销商
            $enzdArr =Member::where("id", "in", $data["member_ids"]) ->column('nickname');
            if(!empty($enzdArr)){
                $model=new Member();
                foreach ($enzdArr as &$v){
                    $v=$model->emoji_decode($v);
                }
            }
        }
        if($data["sende_data"]==1){
            //发送对象:0=用户,1=店铺,2=区域服务商,3=卡经销商,4=分销商
            $enzdArr =Merchant::where("id", "in", $data["member_ids"]) ->column('name');
        }
        if($data["sende_data"]==2){
            //发送对象:0=用户,1=店铺,2=区域服务商,3=卡经销商,4=分销商
            $enzdArr =Regionservice::where("id", "in", $data["member_ids"]) ->column('name');
        }
        if($data["sende_data"]==3){
            //发送对象:0=用户,1=店铺,2=区域服务商,3=卡经销商,4=分销商
            $enzdArr =Dealer::where("id", "in", $data["member_ids"]) ->column('name');
        }
        if($data["sende_data"]==4){
            //发送对象:0=用户,1=店铺,2=区域服务商,3=卡经销商,4=分销商
            $enzdArr =Distributor::where("id", "in", $data["member_ids"]) ->column('name');
        }
        return implode(",", $enzdArr);
    }

}
